/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ModuloConfiguracion;

//import hibernate.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;

import Acceso.Security;

/**
 *
 * @author yngrdyn
 */
public class generarCalendarioGuardiaAction extends org.apache.struts.action.Action {

    /* forward name="success" path="" */
    private static final String SUCCESS = "success";
    private static final String FAILURE = "failure";
    private static final String[] ALLOWED = {"Administrador"};

    /**
     * This is the action called from the Struts framework.
     * @param mapping The ActionMapping used to select this instance.
     * @param form The optional ActionForm bean for this request.
     * @param request The HTTP Request we are processing.
     * @param response The HTTP Response we are processing.
     * @throws java.lang.Exception
     * @return
     */
    @Override
    public ActionForward execute(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {


        if (!Security.validateSession(request, ALLOWED)) {
            Security.privilegeError(response);
            return mapping.findForward("errorPriv");
        }

        generarCalendarioGuardiaForm formBean = (generarCalendarioGuardiaForm) form;

        String sede = request.getParameter("idSede");
        ActionErrors errors = new ActionErrors();

        if (sede.equals("seleccionar")) {
            errors.add("sede_requerida", new ActionMessage("errors.sede_requerida"));
            saveErrors(request, errors);

            return mapping.findForward(FAILURE);
        }

        /*response.setContentType("text/json");
        JSONObject guardiasSede = new JSONObject();
        Guardia_DAO g = new Guardia_DAO();
        guardiasSede.put("Guardias", g.consultarGuardiaSede(sede));
        PrintWriter pw = response.getWriter();
        pw.write(guardiasSede.toString());
        pw.flush();
        pw.close();*/

        System.out.println("\n\nSede = " + sede + "\n\n");

        return mapping.findForward(SUCCESS);
    }
}
